<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:include page="/WEB-INF/views/layouts/header.jsp" />
<style>
.yhgltable ul li span.current{font-weight:bold}
</style>
<script type="text/javascript">
	function toInsert(){
		document.location="/product/createProduct"
	}
	/**
	把指定的一组checkbox所选的值构造为逗号分隔的字符串
	*/
	function getAllValue(group_box) {
		var boxes = document.getElementsByName(group_box);
		var values = "";
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				values += boxes[i].value + ",";
			}
		}
		if (values.length > 0) {
			values = values.substring(0, values.length - 1);
		}
		return values;
	}
	function deleteProduct(){
		var operatorIds = getAllValue("group_box");
		if(!operatorIds){
			alert("请选择需要删除的用户！");
			return;
		}
		$.ajax({
		  url: "/product/delProduct",
		  type:"POST",
		  contentType:"application/x-www-form-urlencoded; charset=utf-8",
		  data: "operatorIds="+operatorIds,
		  dataType: 'text',
		  success: function(data) {
			 var jsonobj=eval('('+data+')');
			 if(jsonobj.state==='1'){
				 alert(jsonobj.result);
				 var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
				 var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
				 var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
				 if(currentPage>=1){
					$(".userContent").load("/product/products?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
				 }
			 }else if(jsonobj.state==='0'){
				 alert(jsonobj.result);
			 }
		  },
		  error: function(XMLHttpRequest, textStatus, errorThrown) {
				 alert("删除失败！");
		  }
		});
	}
	function toUpdate(){
		var boxes = document.getElementsByName("group_box");
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				var operatorId = boxes[i].value;
				break;
			}
		}
		if(!operatorId) {
			alert("请选择需要修改的产品！");
			return ;
		}
		window.location="/product/update/"+operatorId;
	}
	function search(obj){
		var searchText = encodeURIComponent($(obj).prev().val()?$(obj).prev().val():"");
		var selectDepartmentId = $("li.current").attr("data-id")?$("li.current").attr("data-id"):"";
		$(".userContent").load("/account/operators?departmentId="+selectDepartmentId+"&searchText="+searchText+"&rd="+Math.random());
	}
	function prevPage(){
		var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
		var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
		var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
		if(currentPage>1){
			currentPage--;
			$(".userContent").load("/account/operators?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
		}
	}
	function nextPage(){
		var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
		var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
		var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
		var totalPage = parseInt($("[name=totalPage]").val());
		if(currentPage<totalPage){
			currentPage++;
			$(".userContent").load("/account/operators?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
		}
	}
</script>
<!--中间部分开始-->
<div class="main">
	<!-- 左侧 -->
	<jsp:include page="/WEB-INF/views/account/sidebar.jsp" />
	<!-- /左侧 -->
	<div id="iaas_layout_content" class="rightblock">
		<p class="shadow"></p>
		<div class="content">
			<!--默认状态下引用样式ml60，展开后引用样式ml140-->
			<div class="mainblock">
				<div class="tabA">
					<h1>产品管理</h1>
				</div>
				<div class="lineone mt10">
					<span><img src="../../../images/back.png"
						class="prev linkhand" style="cursor:pointer;" onclick="prevPage()" /><img
						src="../../../images/next.png" class="next linkhand"
						style="cursor:pointer;" onclick="nextPage()" />
					</span>
					<div class="btn">
						<a href="javascript:void(0)" onclick="toInsert()"><img
							src="../../../images/xz.gif" />新增</a> <a href="javascript:void(0)"
							onclick="deleteProduct()"><img src="../../../images/del.gif" />删除</a>
						<a href="javascript:void(0)" onclick="toUpdate()"><img
							src="../../../images/xg.gif" />修改</a>
					</div>
					<div class="search">
						<input type="text" name="searchText" /> <img
							src="../../../images/search.png" onclick="search(this)"
							class="linkhand" />
					</div>
				</div>

				<table border="0" cellpadding="0" cellspacing="0" class="yhgltable mt10">
			          <tr>
			            <td rowspan="2" class="userContent" valign="top"><script>$(".userContent").load("/product/products")</script></td>
			          </tr>
			          <tr>
			            <td valign="top">
			            <ul class="dm-menu">
			                
			              </ul>
			              <script>
			              		var jsonArray = eval('${bankFinanceProduct}');
			              		if(jsonArray){
			              			$(".dm-menu").html(buildTree(jsonArray));
			              		}
			              		function buildTree(jsonArray){
			              			var html = "";
			              			html = buildNode(jsonArray[0]);
			              			return html;
			              		}
			              		
			              </script>
			              </td>
			          </tr>
        		</table>
				<div class="lineone mt10">
					<span><img src="../../../images/back.png"
						class="prev linkhand" style="cursor:pointer;" onclick="prevPage()" /><img
						src="../../../images/next.png" class="next linkhand"
						style="cursor:pointer;" onclick="nextPage()" />
					</span>
					<div class="btn">
						<a href="javascript:void(0)" style="cursor:pointer;"
							onclick="toInsert()"><img src="../../../images/xz.gif"
							style="cursor:pointer;" />新增</a> <a href="javascript:void(0)"
							onclick="deleteUser()"><img src="../../../images/del.gif" />删除</a>
						<a href="javascript:void(0)" onclick="toUpdate()"><img
							src="../../../images/xg.gif" />修改</a>
					</div>
					<div class="search">
						<input type="text" name="searchText" /> <img
							src="../../../images/search.png" onclick="search(this)"
							class="linkhand" />
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--底部开始-->
<jsp:include page="/WEB-INF/views/layouts/footer.jsp" />
<!--底部结束-->
</body>
</html>
